/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package vista;

import control.Control;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import modelo.Partida;
import modelo.Solicitud;

/**
 *
 * @author alumneDAM
 */
public class PanelPartidasIniciadas extends javax.swing.JPanel {

    private Control control;

    public PanelPartidasIniciadas(Control control) {
        initComponents();
        this.control = control;
        this.btn_iniciarNuevaPartida.addActionListener(control);
        this.lst_partidasIniciadas.addMouseListener(control);
        this.lst_SolicitudesPartida.addListSelectionListener(control);

    }

    public void rellenarPartidas(ArrayList<Partida> partidas) {
        DefaultListModel<Partida> listModel = new DefaultListModel();
        for (Partida p : partidas) {
            p.toString(control.getJugador().getNickname());

            listModel.addElement(p);

        }
        this.lst_partidasIniciadas.setModel(listModel);
    }

    public void rellenarSolicitudes(ArrayList<Solicitud> solicitudes) {
        DefaultListModel<Solicitud> listModel = new DefaultListModel();
        for (Solicitud p : solicitudes) {
            listModel.addElement(p);
        }
        this.lst_SolicitudesPartida.setModel(listModel);
    }

    public JList getLst_SolicitudesPartida() {
        return lst_SolicitudesPartida;
    }

    public Object recuperarPartida() {
        return lst_partidasIniciadas.getSelectedValue();
    }

    public Object recuperaSolicitud() {
        return lst_SolicitudesPartida.getSelectedValue();
    }

    public Object recuperarPartida1() {
        return lst_partidasIniciadas.getModel().getElementAt(0);
    }

    public int muestraAceptarSolicitud() {
        int salida;

        salida = JOptionPane.showConfirmDialog(this, "¿Aceptas la Solicitud?", "Solicitud", JOptionPane.YES_NO_OPTION);
        return salida;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbl_partidasIniciadas = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lst_partidasIniciadas = new javax.swing.JList();
        lbl_logo = new javax.swing.JLabel();
        btn_iniciarNuevaPartida = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        lst_SolicitudesPartida = new javax.swing.JList();
        lbl_partidasIniciadas1 = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 51));

        lbl_partidasIniciadas.setText("Partidas Iniciadas");

        lst_partidasIniciadas.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lst_partidasIniciadas.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane1.setViewportView(lst_partidasIniciadas);

        lbl_logo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/logo.jpg"))); // NOI18N

        btn_iniciarNuevaPartida.setText("Iniciar Nueva Partida");
        btn_iniciarNuevaPartida.setActionCommand("IniciarNuevaPartida");

        lst_SolicitudesPartida.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lst_SolicitudesPartida.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lst_SolicitudesPartida.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane2.setViewportView(lst_SolicitudesPartida);

        lbl_partidasIniciadas1.setText("Solicitudes de Partida Pendietes");
        lbl_partidasIniciadas1.setToolTipText("");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(lbl_logo, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(btn_iniciarNuevaPartida))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(lbl_partidasIniciadas1, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(lbl_partidasIniciadas, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(10, 10, 10))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbl_logo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbl_partidasIniciadas)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addComponent(lbl_partidasIniciadas1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btn_iniciarNuevaPartida)
                .addGap(20, 20, 20))
        );

        lbl_partidasIniciadas1.getAccessibleContext().setAccessibleName("lbSolicitudes");
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_iniciarNuevaPartida;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lbl_logo;
    private javax.swing.JLabel lbl_partidasIniciadas;
    private javax.swing.JLabel lbl_partidasIniciadas1;
    private javax.swing.JList lst_SolicitudesPartida;
    private javax.swing.JList lst_partidasIniciadas;
    // End of variables declaration//GEN-END:variables
}

//        lbl_partidasIniciadas1.getAccessibleContext().setAccessibleName("lbSolicitudes");
